
#include "debug.h"
#include <stdarg.h>
#include <stdio.h>
#include <windows.h>

HANDLE ScreenBuffer;
bool DebugStartup(){
	HANDLE hStdout;

	if (!AllocConsole()) return FALSE;

	ScreenBuffer=CreateConsoleScreenBuffer(
		FILE_SHARE_READ|FILE_SHARE_WRITE,
		0,
		NULL,
		CONSOLE_TEXTMODE_BUFFER,
		NULL);

	hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 

	return true;		
}

bool DebugShutdown(){
	return true;
}

void DEBUG_PRINT(char* fmt, ...){	
#ifdef _DEBUG
	char Buff[1024];
	va_list	va;
	DWORD	BytesWritten;
	HANDLE	hStdout;

	memset(Buff, 0x00, 1024);
	va_start(va, fmt);
	_vsnprintf_s(Buff, 1024, fmt, va);
	va_end(va);

	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
	
	WriteFile(hStdout, Buff, strlen(Buff), &BytesWritten, NULL);
#endif
}

void DEBUG_PRINTVECT(char *name, irr::core::vector3df vec) {
#ifdef _DEBUG
	DEBUG_PRINT("%s:\tX:[%f]\tY:[%f]\tZ:[%f]\n", name, vec.X, vec.Y, vec.Z);
#endif
}